#pragma once
#include <windows.h>
#include <stdio.h>

#define		MAX_BUFFLEN				2048

class CCritical  
{
public:
	CCritical(){InitializeCriticalSection(&m_cs);};
	virtual ~CCritical(){DeleteCriticalSection(&m_cs);};

public:
	int		Lock(){EnterCriticalSection(&m_cs);return 0;};
	int		Unlock(){LeaveCriticalSection(&m_cs);return 0;};

private:
	CRITICAL_SECTION	m_cs;

};

class CSyncEvent  
{
public:
	CSyncEvent(CCritical* pCS){m_pCS = pCS;m_pCS->Lock();};
	virtual ~CSyncEvent(){m_pCS->Unlock();m_pCS = NULL;};

private:
	CCritical*		m_pCS;

};

class CLogFile
{
public:
	CLogFile(const char* pchFile);
	virtual ~CLogFile();

public:
	BOOL	Log(char* pchMsg, ...);

protected:
	BOOL	CreateFile();
	char*	GetTimer();
	char*	GetLogFile(char* pchFile);

private:
	BOOL	Init(const char* pchFile);  //  .log
private:
	char	m_szFile[MAX_BUFFLEN];
	char	m_szTimer[MAX_BUFFLEN];
	char	m_szBuffer[MAX_BUFFLEN];
	FILE*	m_pFile;
	DWORD	m_dwWriteTimer;

private:
	CCritical	m_cs;

};
